import 'package:flutter/services.dart';

const _regExp = r"^[Za-z0-9_]+$";

/// 只能输入数字和小写字母
class OnlyInputNumberAndLowWorkFormatter extends TextInputFormatter {
  @override
  TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
    if (newValue.text.length > 0) {
      if (RegExp(_regExp).firstMatch(newValue.text) != null) {
        return newValue;
      }
      return oldValue;
    }
    return newValue;
  }
}
